<?php
/**
 * 一个手机上传图片到服务器程序
 * fsockopen(主机名称，端口号码，错误号的接受变量，错误提示的接受变量，超时时间)
 * User: huy
 * Date: 2017/3/9
 * Time: 10:52
 */
$data   = file_get_contents('3.jpg');
$body   = $data;
$type   = 'application/x-www-form-urlencoded';
$length = strlen($body);
$host   = 'www.web2.com';
$port   = 80;
$path   = '/demo3/3/image.php';
//注意： $host.$path     就是完整的url链接。
$fp = fsockopen($host, $port, $error_no, $error_desc, 30);

if($fp){
    fputs($fp, "POST {$path} HTTP/1.1\r\n");
    fputs($fp, "Host: {$host}\r\n");
    fputs($fp, "Content-Type: {$type}\r\n");
    fputs($fp, "Content-Length: {$length}\r\n");
    fputs($fp, "Connection: close\r\n\r\n");
    fputs($fp, $body . "\r\n\r\n");

    $d = '';
    while(!feof($fp)){
        $d .= fgets($fp, 4096);
    }
    fclose($fp);
    echo $d;
}
